/**
 * yield方法演示(让出CPU的执行权)
 */
public class ThreadYield {
    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            //得打当前线程
            Thread cThread=Thread.currentThread();
            for (int i = 0; i <100 ; i++) {
                //让出CPU执行权
                Thread.yield();
                System.out.println("执行了线程:"+cThread.getName());
            }
        },"张三");
                t1.start();
                //创建并动线程
             new Thread(()->{
                 Thread cThread=Thread.currentThread();
                 for (int i = 0; i < 100; i++) {
                     System.out.println("执行线程:"+cThread.getName());
                 }
                },"李四").start();

    }
}
